export function timeToMinutes(time) {
  const [hours, minutes, seconds] = time.split(':').map(Number);
  return hours * 60 + minutes + seconds / 60;
}

// 比较函数
export function compareTimes(a, b) {
  const midday = timeToMinutes('12:00:00');
  const aMinutes = timeToMinutes(a);
  const bMinutes = timeToMinutes(b);

  if (aMinutes >= midday && bMinutes >= midday) {
    // 两者都在12:00:00之后，按正常顺序排序
    return aMinutes - bMinutes;
  } else if (aMinutes < midday && bMinutes < midday) {
    // 两者都在12:00:00之前，按正常顺序排序
    return aMinutes - bMinutes;
  } else {
    // 一个在12:00:00之后，一个在12:00:00之前
    return aMinutes >= midday ? -1 : 1;
  }
}

export function formatDate(date) {
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要加1
  const day = String(date.getDate()).padStart(2, '0');

  return `${year}-${month}-${day}`;
}